package com.momo.epidemic.control;

import com.momo.epidemic.beans.UserInfo;
import com.momo.epidemic.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/user")
public class UserControl {

    public static Logger logger = Logger.getLogger(UserControl.class);
    @Autowired
    public UserService userService;

    @RequestMapping("/login")
    public String login(UserInfo userInfo, Model model){
        logger.debug("**********************************************************************************************");
        logger.debug("login()被执行,userAccount:"+userInfo.getAccount()+",userpassword:"+userInfo.getPassword());
        logger.debug("**********************************************************************************************");

        UserInfo user = this.userService.findByAccount(userInfo.getAccount());
        if (user == null ){
            model.addAttribute("msg","账号不正确");
            return "login";
        }
        if (userInfo.getPassword() == null || userInfo.getPassword() == ""){
            model.addAttribute("msg","请输入密码");
            return "login";
        }
        if (user.getPassword().equals(userInfo.getPassword())) {
//           登录成功
            return "redirect:/main.jsp";
        }
        model.addAttribute("msg","密码不正确");
        return "login";
    }
}
